import { useEffect, Suspense, lazy } from 'react'
import config from '../config.default'
import getStore, { history } from './store';
import { Route, Routes } from "react-router-dom";
import { Provider } from 'react-redux';
import PrivateComponent from '@/components/PrivateComponent';
import { HistoryRouter as Router } from "redux-first-history/rr6";
import { ConfigProvider, Spin } from 'antd';
import zhCN from 'antd/locale/zh_CN'
import { persistStore } from 'redux-persist';
import { PersistGate } from 'redux-persist/lib/integration/react';
import { setmultiple } from './utils/util';
import './App.css';
import 'dayjs/locale/zh-cn';
import ForgetPwd from './pages/forgetPwd';
const Login = lazy(() => import('@/pages/login'));
const AppLayout = lazy(() => import('@/layouts'));
const NotFound = lazy(() => import('@/pages/404'));
const appStore = getStore();
const persist = persistStore(appStore);
//设置默认页面标题
document.title = config.layout.defaultTitle
window.onresize = function () {
  setmultiple();
}
function App() {
  useEffect(() => {
    setmultiple()
    return
  }, [])
  return (
    <Provider store={appStore}>
      <PersistGate persistor={persist}>
        <ConfigProvider locale={zhCN}>
          <Router history={history}>
            <Suspense fallback={<Spin size="large"><div style={{ minHeight: '100vh', minWidth: '100vw' }}></div></Spin>}>
              <Routes >
                <Route path="/404" element={<NotFound />}></Route>
                {
                  config.loginPermissions.enable &&
                  <Route path="/login" element={<Login />}></Route>
                }
                {
                  config.loginPermissions.enable &&
                  <Route path="/forgetPwd" element={<ForgetPwd />}></Route>
                }
                <Route path="/*" element={
                  <PrivateComponent>
                    <AppLayout />
                  </PrivateComponent>
                }></Route>
              </Routes>
            </Suspense>
          </Router>
        </ConfigProvider>
      </PersistGate>
    </Provider>
  )
}

export default App
